package com.gxw.rxjavatest.utils;

import android.graphics.Bitmap;
import android.util.Base64;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * @author 作者：晓炜
 * @version 创建时间：2015-6-1上午11:20:40 类说明:将Bitmap转换成String
 */

public class BitToStr {

    private static String TAG = BitToStr.class.toString();

    public static String initBitToStr(Bitmap bitmap) {
        String replace = "";
        try {

            ByteArrayOutputStream out = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
            out.flush();
            out.close();
            byte[] buffer = out.toByteArray();// 将图片转换为二进制流
            byte[] encode = Base64.encode(buffer, Base64.DEFAULT);// 对二进制流进行编码

            String photo = new String(encode);// 将编码后的流转换为字符串
            replace = photo.replaceAll("\\+", "%2B");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return replace;
    }

    public static void translate() {


    }

}
